package com.bac.rentmap.web.controller.ad.manage;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bac.rentmap.ad.flat.FlatAd;
import com.bac.rentmap.ad.publisher.AdPublisherService;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.bac.rentmap.ad.flat.FlatAdDao;

public class FlatAdDeleteController extends AbstractController {
    private FlatAdDao flatAdDao;
    private AdPublisherService adPublisherService;

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        String secureId = request.getParameter("secureId");
        FlatAd flatAd = flatAdDao.loadBySecureId(secureId);
        flatAdDao.deleteBySecureId(secureId);
        adPublisherService.unregisterAd(flatAd.getPhone());
        return new ModelAndView("ad/manage/deleteMessage");
    }

    @Required
    public void setFlatAdDao(FlatAdDao flatAdDao) {
        this.flatAdDao = flatAdDao;
    }

    @Required
    public void setAdPublisherService(AdPublisherService adPublisherService) {
        this.adPublisherService = adPublisherService;
    }
}
